package ece.com.controler;

import java.awt.Color;
import java.util.Observable;
import java.util.Observer;

import ece.com.gui.Gui_Landing;
import ece.com.intefaces.ILandingGear;
import ece.com.model.Door;
import ece.com.model.Gear;
import ece.com.model.LandingGear;
import ece.com.model.TimeLanding;

public class LandingGearControler implements Observer, ILandingGear{

	private LandingGear l=null;
	private Gui_Landing guiLanding;
	
	public LandingGearControler(LandingGear l, Gui_Landing guiGear){
		this.l=l;
		this.guiLanding=guiGear;
	}
	
	@Override
	public void update(Observable obs, Object obj) {
		
		
//		System.out.println("LandingGearControler");
		
		if(obs instanceof LandingGear){
			l = (LandingGear) obs;
			
			if(!l.isStopAll()){
				//action
				String action = (String) obj;
//				System.out.println(action);
				
				//GEAR
				Gear g = l.getG();
				if(action.equals(ACTION_GEAR_DOWN_TO_UP) || action.equals(ACTION_GEAR_UP_TO_DOWN)){
					//vue majColor maneuvering
					guiLanding.majColorGear(Color.ORANGE);
				}
				else if(action.equals(ACTION_GEAR_LOCK_DOWN)){
					//vue majColor down
					guiLanding.majColorGear(Color.GREEN);
				}
				else if(action.equals(ACTION_GEAR_LOCK_UP)){
					//vue majColor up
					guiLanding.majColorGear(Color.BLACK);
				}
				
				
				//DOOR
				Door d = l.getD();
				if(d.isClose())
					guiLanding.majColorDoor(Color.BLACK);
				else if ((d.isFromDownToHight() || d.isFromHightToDown()) && d.isUnlock())
					guiLanding.majColorDoor(Color.ORANGE);
				else if (d.isOpen()){
					guiLanding.majColorDoor(Color.GREEN);
				}
	//			System.out.println(l.getG());
	//			System.out.println(l.getD());
			}
		}
		
		
	}

	@Override
	public String toString() {
		return "LandingGearControler [l=" + l + ", guiLanding=" + guiLanding
				+ "]";
	}

}
